package com.itmeima.text6;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;

public class Demo1 {
    public static void main(String[] args) {
        HashMap<String, Object> map = new HashMap<>();
        map.put("id", "heima001");
        map.put("name", "张三");
        map.put("age", 23);
        map.put("birthday", "1999-09-09");

        //学生对象
        Student s = new Student();
        Class<? extends Student> aClass = s.getClass();
        //属性    一一对应
        //遍历集合

        Method[] methods = aClass.getMethods();
        map.forEach((k, v) -> {
            String methodName = "set" + k.substring(0,1).toUpperCase() + k.substring(1);

            for (Method method : methods) {
                if (methodName.equals(method.getName())){
                    try {
                        method.invoke(s,v);
                    } catch (IllegalAccessException e) {
                        e.printStackTrace();
                    } catch (InvocationTargetException e) {
                        e.printStackTrace();
                    }
                }
            }

        });

        System.out.println(s);
    }

}
